// Includes:
#include "TAgent.h"
// Libraries:
#include <iostream>

/** 
* PUBLIC:
* Default constructor.
**/
TAgent::TAgent(void)
{
	init();
}

TAgent::~TAgent(void)
{
	delete _vecInput;
	delete _vecMidLayer;
	delete _vecWeight;
}

/**
* PUBLIC:
* Initialize values.
**/
void TAgent::init()
{	
	// Init data:
	_output = 0.f;

	// Init vectors:
	_vecInput = new std::vector<float>();
	_vecWeight = new std::vector<float>();
	_vecMidLayer = new std::vector<float>();
		
	//Add (random) testdata:
	_vecInput->push_back(110.3f);
	_vecInput->push_back(140.8f);
	_vecInput->push_back(122.4f);

	// 6 weights:
	_vecWeight->push_back(0.5f);
	_vecWeight->push_back(1.0f);
	_vecWeight->push_back(1.0f);
	_vecWeight->push_back(0.5f);
	_vecWeight->push_back(1.5f);
	_vecWeight->push_back(1.5f);

	// Init success:
	std::cout << "Init success! \n";

	// Printing the predicted output:
	std::cout << "Predicted output: " << predictOutput() << "\n";
}

/**
* PRIVATE:
* Predicts output.
**/
float TAgent::predictOutput()
{
	//float layer1 = 0.f;
	//float layer2 = 0.f;

	//Calculate midlayer:
	int count = 0;
	float layerTmp;
	for(int i = 0; i < _vecInput->size() - 1; i++)
	{
		layerTmp = 0.f;
		// since it is running _vecInput - 1 times, one have to divide:
		for(int j = 0; j < _vecWeight->size() / (_vecInput->size() - 1); j++)
		{
			layerTmp += _vecInput->at(i) * _vecWeight->at(count);
			count++;
		}
		layerTmp = layerTmp / static_cast<float>(_vecInput->size());
		_vecMidLayer->push_back(layerTmp);
	}

	// Set _output: 
	for(int i = 0; i < _vecMidLayer->size(); i++)
	{
		_output += _vecMidLayer->at(i);
	}
	_output = _output / static_cast<float>(_vecMidLayer->size());

	//// Create midlayers:
	//int count = 0;
	//for(int i = 0; i < _vecInput->size(); i++)
	//{
	//	layer1 += _vecInput->at(i) * _vecWeight->at(count);
	//	count++;
	//}
	//for(int i = 0; i < _vecInput->size(); i++)
	//{
	//	layer2 += _vecInput->at(i) * _vecWeight->at(count);
	//	count++;
	//}

	//layer1 = layer1/_vecInput->size();
	//layer2 = layer2/_vecInput->size();

	//_output = (layer1 + layer2) / 2.f;
	return _output;
}
